<template>
  <div class="adviceSong">
    <div class="title">
      <span>
        推荐歌单
        <i class="iconfont iconarrow-right"></i>
      </span>
    </div>
    <div class="songbody">
      <div v-for="item in songConfig" :key="item.id" class="songDetail">
        <div @click="goSongDetail(item.id)">
          <div class="songCount">
            <i class="iconfont icon24gl-play"></i>
            <span>{{playCount(item.playCount)}}</span>
          </div>

          <img :src="item.picUrl" alt srcset width="150" height="150" />
          <div class="songPlay">
            <i class="iconfont iconbofang"></i>
          </div>
          <div class="songName">
            <span>{{item.name}}</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script setup lang="ts">
type adviceSongT = {
  id: number
  name: string
  picUrl: string
  playCount: number
}
import { onMounted, ref, computed } from 'vue'
import axios from '@/http.ts'
import { useRouter } from 'vue-router'
onMounted(() => {
  getadviceSong()
})
const songConfig = ref<Array<adviceSongT>>([])
const playCount = computed(() => count => {
  return count > 10000 ? Math.ceil(count / 10000) + '万' : count
})
const router = useRouter()
const goSongDetail = id => {
  router.push('/home/playList/' + id)
}
const getadviceSong = () => {
  axios
    .get('/personalized', {
      params: {
        limit: 10
      }
    })
    .then(res => {
      res.data.code === 200 && (songConfig.value = res.data.result)
    })
}
</script>

<style scoped lang="less">
.adviceSong {
  overflow: scroll;
  padding: 16px;
  .title {
    color: #b2b2b2;
    overflow: hidden;
    font-weight: bolder;
    margin-bottom: 10px;
    margin-left: 20px;
    &:hover {
      color: #fff;
      cursor: pointer;
    }
  }
  .songbody {
    display: flex;
    flex-wrap: wrap;
    .songDetail {
      position: relative;
      text-align: center;
      flex-basis: 190px;
      color: #b3b3b3;
      .songCount {
        position: absolute;
        font-size: 12px;
        font-weight: bolder;
        color: #fff;
        right: 30px;
        top: 3px;
        .iconfont {
          font-size: 12px;
          margin-right: 3px;
        }
      }
      .songPlay {
        width: 30px;
        height: 30px;
        background-color: rgba(255, 255, 255, 0.8);
        position: absolute;
        border-radius: 50%;
        overflow: hidden;
        bottom: 100px;
        right: 30px;
        transition: opacity 0.15s;
        opacity: 0;
        &:hover {
          opacity: 1;
          cursor: pointer;
        }
        &::after {
          position: absolute;
          content: '';
          filter: blur(30px);
          background-attachment: scroll;
          width: 30px;
          background-size: 150px 150px;
          background-repeat: no-repeat;
          background-position: -110px -104px;
          left: 0;
          background-color: #b3b3b3;
          height: 30px;
        }
        .iconfont {
          font-size: 13px;
          position: absolute;
          color: red;
          left: 2px;
          top: 8px;
          right: 0;
          bottom: 0;
          margin: auto;
        }
      }
      .songName {
        padding: 0 19px;
        text-align: left;
        font-size: 13px;
        font-weight: bolder;
        height: 80px;
        span {
          overflow: hidden;
          text-overflow: ellipsis;
          display: -webkit-box;
          -webkit-line-clamp: 2;
          -webkit-box-orient: vertical;
          &:hover {
            color: #fff;
            cursor: pointer;
          }
        }
      }
      img {
        border-radius: 6px;
        &:hover {
          opacity: 1;
          cursor: pointer;
        }
        &:hover + .songPlay {
          opacity: 1;
          cursor: pointer;
        }
      }
    }
  }
}
</style>